$btn = "#start";
voice = {
    localId:''
};

$(function(){
    $($btn).on('touchstart',function(event){
        event.preventDefault();
        START = new Date().getTime();
        recordTimer = setTimeout(function(){
            wx.startRecord({
                success:function(){
                    localStorage.rainAllowRecord = 'true';
                },
                cancel:function(){
                    alert("拒绝授权录音");
                }
            });
        },300);
    });
    $($btn).on('touchend',function(event){

        event.preventDefault();
        END = new Date().getTime();

        if((END-START)<300){
            END = 0;
            START = 0;
            clearTimeout(recordTimer);
        }else{
            wx.stopRecord({
                success:function(res){
                    voice.localId = res.localId;
                    wx.playVoice({localId:voice.localId});
                    uploadVoice();
                },
                fail:function(res){
                    alert(JSON.stringify(res));
                }
            });
        }

    });
});
function uploadVoice(){
    wx.uploadVoice({
        localId: voice.localId,
        isShowProgressTips: 1,
        success: function (res) {
            $.ajax({
                url: '/Upload.php',
                type: 'post',
                data: res,
                success: function (data) {
                    console.log(data);
                },
                error: function (xhr, errorType, error) {
                    console.log(error);
                }
            });
        }
    });
}
